package com.jk.util.autotest.util;

/**
 * @author Administrator
 */
public class JsonUtil {

    public static Long getTl(String json){
        if(!checkJson(json)){
            return null;
        }
        int indexStart = json.indexOf("\"tl\":")+5;
        int indexEnd = indexStart;
        while (Character.isDigit(json.charAt(indexEnd))){
            indexEnd++;
        }
        String result = json.substring(indexStart,indexEnd);
        return Long.valueOf(result);
    }


    public static Integer getTotal(String json){
        if(!checkJson(json)){
            return null;
        }
        int indexStart = json.indexOf("\"total\":")+8;
        int indexEnd = indexStart;
        while (Character.isDigit(json.charAt(indexEnd))){
            indexEnd++;
        }
        String result = json.substring(indexStart,indexEnd);
        return Integer.valueOf(result);
    }


    private static boolean checkJson(String json){
        if(json == null || "".equals(json)){
            return false;
        }else {
            return true;
        }
    }
}
